//
//  V_VideoTableViewCell.m
//  FitTime
//
//  Created by dllo on 16/3/31.
//  Copyright © 2016年 赵建平. All rights reserved.
//

#import "V_VideoTableViewCell.h"

@implementation V_VideoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
     
        self.backImageView = [UIImageView new];
        [self.contentView addSubview:self.backImageView];
        
        self.leftPlanLable = [UILabel new];
        [self.contentView addSubview:self.leftPlanLable];
        
        self.waterView = [UIView new];
        [self.contentView addSubview:self.waterView];
        
        self.rightPlanLable = [UILabel new];
        [self.contentView addSubview:self.rightPlanLable];
        
        self.smallTitleLable = [UILabel new];
        [self.contentView addSubview:self.smallTitleLable];
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
        make.width.equalTo(self.contentView.mas_width);
        make.height.equalTo(self.contentView.mas_height);
    }];
    
    
    [self.smallTitleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView.mas_centerX);
        make.centerY.equalTo(self.contentView.mas_centerY).offset(-20);
        make.size.mas_equalTo(CGSizeMake(SCREENWIDTH, 40));
    }];
    
    [self.waterView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView.mas_centerX).offset(-13);
        make.centerY.equalTo(self.contentView.mas_centerY).offset(30);
        make.size.mas_equalTo(CGSizeMake(60, 20));
    }];
    
    [self.leftPlanLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.waterView.mas_left).offset(-5);
        make.centerY.equalTo(self.waterView.mas_centerY);
        make.height.equalTo(@20);
        
    }];
    
    [self.rightPlanLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.waterView.mas_right).offset(5);
        make.centerY.equalTo(self.waterView.mas_centerY);
        make.height.equalTo(@20);
    }];

    self.smallTitleLable.textColor = [UIColor whiteColor];
    self.smallTitleLable.textAlignment = NSTextAlignmentCenter;
    self.smallTitleLable.font = [UIFont systemFontOfSize:25 weight:2];
    
    self.leftPlanLable.textColor = [UIColor whiteColor];
    self.leftPlanLable.textAlignment = NSTextAlignmentCenter;
    self.leftPlanLable.font = [UIFont systemFontOfSize:15 weight:1];
    
    self.rightPlanLable.textColor = [UIColor whiteColor];
    self.rightPlanLable.textAlignment = NSTextAlignmentCenter;
    self.rightPlanLable.font = [UIFont systemFontOfSize:15 weight:1];

    
}

- (void)setVideoModel:(VideoModel *)videoModel {
    _videoModel = videoModel;
    NSString *photoString = [NSString stringWithFormat:@"http://ft-video.fit-time.cn/program_%@.png@!480", videoModel.ID];
    [self.backImageView sd_setImageWithURL:[NSURL URLWithString:photoString]];
    
    self.smallTitleLable.text = videoModel.title;

    NSMutableString *orderString = [NSMutableString stringWithFormat:@"%@", videoModel.subtitle];
    self.leftPlanLable.text = [NSString stringWithFormat:@"%d次 / 难度", orderString.intValue];
    
    for (int i = 0; i < videoModel.difficulty; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake( 20 * i, 0, 20, 20)];
        imageView.image = [UIImage imageNamed:@"water_b"];
        [self.waterView addSubview:imageView];
    }
    for (int i = (int)videoModel.difficulty; i < 3 ; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake( 20 * i, 0, 20, 20)];
        imageView.image = [UIImage imageNamed:@"water_w"];
        [self.waterView addSubview:imageView];
    }
    
    self.rightPlanLable.text = [NSString stringWithFormat:@"/%ld人练过", (long)videoModel.playCount];

}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
